home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / FrameFormatter.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  8.9 KB  |  331 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        FrameFormatter.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _FrameFormatter_
  18. #define _FrameFormatter_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _TextensionCommon_
  25. #include "TextensionCommon.h"
  26. #endif
  27.  
  28.  
  29. #ifndef _Array_
  30. #include "Array.h"
  31. #endif
  32.  
  33.  
  34. #ifndef _ObjectsRanges_
  35. #include "ObjectsRanges.h" //for CRanges
  36. #endif
  37.  
  38. //***************************************************************************************************
  39.  
  40. struct TLineHiteGroup { //lines having the same lineHiteInfo
  41.     long groupCountLines; //count of lines in this group
  42.     short lineHite;
  43.     short lineAscent;
  44.     
  45.     #ifdef txtnScal
  46.     short scaledHite;
  47.     short scaledAscent;
  48.     #endif
  49. };
  50. typedef TLineHiteGroup* TLineHiteGroupPtr;
  51.  
  52. //*************************************************************************************************
  53.  
  54.  
  55. #ifdef txtnMultiFrames
  56. typedef short TFrameEditFlags;
  57.  
  58. //constant for T1FrameEditInfo flags
  59.  
  60. const TFrameEditFlags kInvalidWholeFrame = 1; //need redraw the whole frame
  61.  
  62. const TFrameEditFlags kInvalidFrameFootNotes = 1 << 1;
  63.  
  64. //• constants 1 << 2 through 1 << 7 are reserved for future "invalid content parts" bits
  65.  
  66. const TFrameEditFlags kInvalidMask = 0x00FF;
  67.  
  68. const TFrameEditFlags kInvalidContentMask = 0x00FE; //used internally
  69.  
  70. const TFrameEditFlags kInvalidFrameText = 1 << 8; //need redraw the text inside the frame
  71.  
  72.  
  73. struct T1FrameEditInfo {
  74.     long     frameNo;
  75.     TFrameEditFlags flags;
  76.     long invalMessage;
  77.     long     hiteModif; //scaled
  78.     short overflowIn; //scaled
  79.     short overflowOut; //scaled
  80. };
  81.  
  82. const short kMaxEditFrames = 50;
  83.  
  84.  
  85. class CFrameEditInfo : private SingleObject {
  86.     public :
  87.         CFrameEditInfo() {fCount = 0;}
  88.         
  89.         inline void BeginEdit() {
  90.             fCount = 0;
  91.             fIterateIndex = 0;
  92.         }
  93.         
  94.         inline void EndEdit() {fCount = 0;}
  95.         
  96.         inline GetCount() {return fCount;}
  97.         
  98.         T1FrameEditInfo* CatchFrame(long frameNo);
  99.         
  100.         Boolean GetEditInfoPtr(long frameNo, T1FrameEditInfo** editInfo
  101.                                                         , TFrameEditFlags mask = kInvalidFrameText+kInvalidWholeFrame) const;
  102.     
  103.         T1FrameEditInfo* GetNext();
  104.     
  105.         void SetEditFlag(TFrameEditFlags flagVal, long startFrame = 0, short count = kMaxInt);
  106.         
  107.     private:
  108.         short fCount;
  109.         T1FrameEditInfo fEditInfo[kMaxEditFrames];
  110.         
  111.         long fFirstFrame;
  112.         long fLastFrame;
  113.         
  114.         short fIterateIndex;
  115. };
  116.  
  117. extern CFrameEditInfo gFrameEditInfo;
  118. //*************************************************************************************************
  119.  
  120. //const for CFormatReflowLines SetReflowType and GetReflowType
  121. const char kNoReflow = 0;
  122. const char kOverflow = 1;
  123. const char kUnderflow = 2;
  124.  
  125. class CFormatReflowLines : private SingleObject { //lines reflowing between frames and need horiz formatting
  126.     public:
  127.         CFormatReflowLines() {this->Reset();}
  128.         
  129.         void Reset();
  130.         
  131.         void SetFirst(long lineNo);
  132.         void SetLast(long lineNo);
  133.         
  134.         Boolean GetFirst(long* lineNo) const;
  135.         Boolean GetLast(long* lineNo) const;
  136.         
  137.         inline void SetReflowFlag(Boolean flag) {fAllowReflow = flag;}
  138.         inline Boolean GetReflowFlag() const {return fAllowReflow;}
  139.         
  140.         inline void SetReflowType(char theType) {fReflowType = theType;}
  141.         inline char GetReflowType() const {return fReflowType;}
  142.         
  143.     private:
  144.         long fFirstLine;
  145.         long fLastLine;
  146.         Boolean fAllowReflow;
  147.         char fReflowType; //kOverflow or kUnderflow
  148. };
  149. //*************************************************************************************************
  150. #endif
  151.  
  152.  
  153.  
  154. class    CLinesHites    : public CArray {
  155. public:
  156.     CLinesHites();
  157.     
  158.     void     ILinesHites();
  159.     
  160.     virtual void FreeData();
  161.  
  162.     #ifdef txtnScal
  163.     void GetLineHiteInfo(long lineNo, TLineHiteInfo* lineHiteInfo, Boolean scaled=true) const;
  164.     #else
  165.     void GetLineHiteInfo(long lineNo, TLineHiteInfo* lineHiteInfo) const;
  166.     #endif
  167.     
  168.     #ifdef txtnMultiFrames
  169.     virtual OSErr InsertLine(const TLineHiteInfo* lineHiteInfo, CFormatReflowLines* formatReflowLines,
  170.                                                         long lineNo = -1);
  171.     virtual OSErr SetLineHiteInfo(const TLineHiteInfo* lineHiteInfo, long lineNo
  172.                                                             , CFormatReflowLines* formatReflowLines);
  173.     virtual void RemoveLines(long countLines, long lineNo, CFormatReflowLines* formatReflowLines);
  174.     
  175.     #else
  176.     virtual OSErr InsertLine(const TLineHiteInfo* lineHiteInfo, long lineNo = -1);
  177.     virtual OSErr SetLineHiteInfo(const TLineHiteInfo* lineHiteInfo, long lineNo);
  178.     virtual void RemoveLines(long countLines, long lineNo);
  179.     #endif
  180.     
  181.     #ifdef txtnScal
  182.     long Pixel2Line(long* vPix, Boolean scaled, long lineNo = 0
  183.                                     , TLineHiteGroupPtr* hiteGroupPtr = nil, long* groupLineIndex = nil) const;
  184.  
  185.     long Hite2CountLines(const TLineHiteGroupPtr groupPtr, long groupLineNo, Boolean scaled, long* hite) const;
  186.  
  187.     long    GetLinesHite(long firstLine, long lastLine, Boolean scaled=true) const;
  188.  
  189.     long GetTotalLinesHite(Boolean scaled = true) const;
  190.     
  191.     virtual void SetVScale(short numer, short denom);
  192.     
  193.     #else
  194.     long Pixel2Line(long* vPix, long lineNo = 0
  195.                                     , TLineHiteGroupPtr* hiteGroupPtr = nil, long* groupLineIndex = nil) const;
  196.  
  197.     long Hite2CountLines(const TLineHiteGroupPtr groupPtr, long groupLineNo, long* hite) const;
  198.  
  199.     long GetLinesHite(long firstLine, long lastLine) const;
  200.  
  201.     inline long GetTotalLinesHite() const {return fTotalHite;}
  202.     #endif
  203.     
  204.     
  205.     inline long CountLines() const {return fLastLineIndex+1;}
  206.             
  207. protected:
  208.     #ifdef txtnScal
  209.     short fNumer;
  210.     short fDenom;
  211.     #endif
  212.     
  213.     
  214. private:
  215.     long fTotalHite;
  216.     /*to optimize the call of GetLinesHite if required all text hite, fTotalHite is kept scaled
  217.     according to the sclae factor.*/
  218.     
  219.     long fLastLineIndex;
  220.     
  221.     TLineHiteGroupPtr Line2HiteGroup(long* lineNo, long* groupNo =nil) const;
  222.     TLineHiteGroupPtr Pixel2HiteGroup(long* vPix, long* groupLineNo) const;
  223.     
  224.     Boolean EqualGroup(long groupIndex, const TLineHiteGroupPtr groupPtr) const;
  225.     Boolean EqualGroup(long group1Index, long group2Index) const;
  226.     
  227.     Boolean Concat(long group1Index, long group2Index, const TLineHiteGroupPtr groupPtr = nil);
  228.     
  229.     #ifdef txtnScal
  230.     void CalcScaledHiteInfo(TLineHiteGroup* groupPtr) const;
  231.     #endif
  232. };
  233. //*************************************************************************************************
  234.  
  235. class    CFrameFormatter    : public CLinesHites {
  236.     public:
  237.         CFrameFormatter();
  238.         
  239.         inline void IFrameFormatter() {this->ILinesHites();}
  240.         
  241.         //•override
  242.         
  243.         //•own members
  244.         
  245.         //following 2 members : some descendents may want to keep some char offsets (footNotes, frame breaks..)
  246.         inline void SetLineEnds(const CRanges* lineEnds) {fLineEnds = lineEnds;}
  247.         virtual void ReplaceCharRange(long offset, long oldLen, long newLen, Boolean newRuns = true);
  248.         /*"newRuns" false ==> the range "offset..offset+oldLen" will be replace by the same run at
  249.         "offset" (not used if newLen is 0)
  250.         */
  251.         
  252.         virtual void SetFrameHite(long frameNo, short newHite) = 0; //newHite is non scaled
  253.         virtual short GetFrameHite(long frameNo) const = 0; //returns a non scaled value
  254.         
  255.         #ifdef txtnScal
  256.         virtual long GetFrameTextHite(long frameNo, Boolean scaled = true) const = 0;
  257.         #else
  258.         virtual long GetFrameTextHite(long frameNo) const = 0;
  259.         #endif
  260.         
  261.         #ifdef txtnMultiFrames
  262.         Boolean TestFrameOverflow(long lineNo, short newHite);
  263.         //returns true if an overflow will occur if the line hite of "lineNo" is modified to "newHite"
  264.         virtual OSErr ForceOverflow(long lineNo) = 0;
  265.         #endif
  266.         
  267.         virtual OSErr Format();
  268.         
  269.         virtual long GetCountFrames() const = 0;
  270.         
  271.         virtual Boolean GetFrameLineRange(long frameNo, TOffsetPair* frameLines) const = 0;
  272.         //returns false if no lines in the frame
  273.         
  274.         virtual long Line2Frame(TOffset offset) const = 0;
  275.         
  276.         #ifdef txtnMultiFrames
  277.         Boolean GetFrameCharRange(long frameNo, TOffsetPair* frameChars) const;
  278.         
  279.         long Char2Frame(TOffset charOffset) const;
  280.  
  281.         //editing members
  282.         virtual void BeginEdit();
  283.         virtual void CatchFrame(long frameNo);
  284.         virtual T1FrameEditInfo* GetNextFrameEditInfo();
  285.         virtual void EndEdit();
  286.         #endif
  287.         
  288.     protected:
  289.         const CRanges* fLineEnds;
  290.         
  291.     private:
  292. };
  293. //*************************************************************************************************
  294.  
  295. class CMonoFrameFormatter : public CFrameFormatter {
  296.     public:
  297.         CMonoFrameFormatter();
  298.         
  299.         inline void IMonoFrameFormatter() {this->IFrameFormatter();}
  300.  
  301.         //•override
  302.         
  303.         virtual void SetFrameHite(long frameNo, short newHite);
  304.         virtual short GetFrameHite(long frameNo) const;
  305.         
  306.         
  307.         #ifdef txtnScal
  308.         virtual long GetFrameTextHite(long frameNo, Boolean scaled = true) const;
  309.         #else
  310.         virtual long GetFrameTextHite(long frameNo) const;
  311.         #endif
  312.         
  313.         #ifdef txtnMultiFrames
  314.         virtual OSErr ForceOverflow(long lineNo);
  315.         #endif
  316.         
  317.         virtual long GetCountFrames() const;
  318.  
  319.         virtual Boolean GetFrameLineRange(long /*frameNo*/, TOffsetPair* frameLines) const;
  320.  
  321.         virtual long Line2Frame(TOffset offset) const ;
  322.         
  323.         #ifdef txtnMultiFrames
  324.         virtual void CatchFrame(long frameNo);
  325.         virtual T1FrameEditInfo* GetNextFrameEditInfo();
  326.         #endif
  327. };
  328. //*************************************************************************************************
  329.  
  330. #endif
  331.